// 网易深度遍历
const tree = {
    name: 'root',
    children: [
        {
            name: 'c1',
            children: [
                {
                    name: 'c11',
                    children: []
                },
                {
                    name: 'c12',
                    children: []
                }
            ]
        },
        {
            name: 'c2',
            children: [
                {
                    name: 'c21',
                    children: []
                },
                {
                    name: 'c22',
                    children: []
                }
            ]
        }
    ]
}


function dfs(root){
    let result =[],stack = [];

    if(!root){
        return []
    }   

    stack.push(root);

    while(stack.length){
        let node = stack.pop();
        if(node == null) continue;
        result.push(node.name);
        // 栈先进后出，从后面先进
        for(let i = node.children.length-1;i>=0;i--){
            stack.push(node.children[i])
        }
    }

    return result;
}

console.log(dfs(tree))